package com.example.bnuzzu.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bnuzzu.common.dto.HouseListDto;
import com.example.bnuzzu.common.dto.SearchDto;
import com.example.bnuzzu.entity.Houseinfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author BNUZZU
 * @since 2021-04-13
 */
@Repository
public interface HouseinfoMapper extends BaseMapper<Houseinfo> {
    /**
     * 房屋搜索页面分页查询 返回列表 一页6个数据
     * @param page 分页对象
     * @param state 状态
     * @return Page 分页查询结果
     */
    @Select("SELECT houses.* , users.username ,image.mainimage, (SELECT COUNT(*)+1 FROM orderinfo WHERE HouseID = houses.HouseID AND OrderStatus = 1) as friends " +
            "FROM userinfo users,houseinfo houses,houseimage image " +
            "WHERE houses.housestate= #{state} AND houses.deleted = 0 " +
            "AND users.UserID = houses.UserID " +
            "AND houses.houseid = image.houseid ORDER BY houses.updatetime DESC ")
    IPage<HouseListDto> selectPageVo(Page<?> page, Integer state);

    /**
     * 房屋搜索页面待条件分页查询 返回列表 一页6个数据
     * @param page 分页对象
     * @param state 状态
     * @param searchDto 条件
     * @return Page 分页查询结果
     */
    IPage<HouseListDto> searchPageVo(Page<?> page, SearchDto searchDto, Integer state);

    @Select("SELECT houses.* , users.username ,image.mainimage, (SELECT COUNT(*)+1 FROM orderinfo WHERE HouseID = houses.HouseID AND OrderStatus = 1) as friends " +
            "FROM userinfo users,houseinfo houses,houseimage image " +
            "WHERE houses.deleted = 0 AND users.UserID = houses.UserID " +
            "AND houses.houseid = image.houseid ORDER BY houses.housestate,houses.updatetime DESC ")
    List<HouseListDto> getAllhouse();

}
